package com.yidu.controller;

import com.yidu.entity.WorkUser;
import com.yidu.service.WorkUserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 任俊杰
 * @version 1.0
 * @date 2022/8/21
 */
@RestController
public class WorkUserController {
    @Resource
    private WorkUserService workUserService;


    /**
     * 分页
     * @param page
     * @param limit
     * @return
     */
    //这只是从数据库查询的一个方法，跟跳转界面没关系
    @RequestMapping("/query")
    public Map query( int page, int limit, WorkUser workUser){
        System.out.println(workUser.getUsername()+"pppppp");
        System.out.println("进来了query的方法");

        //查询加分页
        List<WorkUser> userList = workUserService.query(page,limit,workUser);

        //查行数
        int count = workUserService.queryCount(workUser);
        System.out.println("行数"+count);
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",userList);
        return map;
    }

    //用户新增
    @RequestMapping("/addUser")
    public int addUser(WorkUser workUser){
        System.out.println("user===="+workUser);//这句话证明进了这个控制器
        int i = workUserService.addUser(workUser);
        System.out.println("i===="+i);
        return i;
    }

    //修改
    @RequestMapping("/updateUser")
    public int updateUser(WorkUser workUser){
        System.out.println("进来了修改的方法"+workUser);
        int i = workUserService.updateUser(workUser);

        if(i>0){
            System.out.println("修改成功"+i);
        }else{
            System.out.println("修改失败"+i);
        }
        return i;
    }

    //多个删除
    @RequestMapping("/deleteUser")
    public int deleteUser(String userid){
        System.out.println("进来了删除的方法"+userid);
        int i = workUserService.deleteUser(userid);

        if(i>0){
            System.out.println("删除成功"+i);
        }else{
            System.out.println("删除失败"+i);
        }
        return i;
    }



   /* //一个删除
    @RequestMapping("/deleteUser1")
    public int deleteUser1(Integer userid){
        System.out.println("进来了一个删除的方法"+userid);
        int i = workUserService.deleteUser(String.valueOf(userid));

        if(i>0){
            System.out.println("删除成功"+i);
        }else{
            System.out.println("删除失败"+i);
        }
        return i;
    }*/

}
